{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Single Qubit Characterization Sequences\n",
    "Simple spectroscopy and coherence experiments on a single qubit."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Initial setup\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from QGL import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "See Auspex [example notebooks](https://github.com/BBN-Q/Auspex/tree/develop/doc/examples) on how to configure a channel library.\n",
    "\n",
    "For the examples in this notebook, we will use a pre-generated channel library:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cl = ChannelLibrary(db_resource_name=\"./example.sqlite\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Initialize a new qubit named `q1` and assign it to variable `q`.\n",
    "\n",
    "*(Note that q1 was already defined in the example channel library, ignore the message that a database item with this name already exists.)*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q = cl.new_qubit('q1')  #initialize qubit, e.g. \"q1\", \"q2\", etc. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sequences"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pulsed spectroscopy sequence\n",
    "A single sequence with a long saturating pulse to find qubit transitions. The ``specOn`` option turns the saturation pulse on/off as this sequence is also useful with just a readout pulse for cavity spectroscopy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "PulsedSpec(q, specOn=True, showPlot=True) #with a Pi/saturation pulse if specOn = True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Rabi Nutation sequences\n",
    "For spectroscopy or calibration purposes we can perform a variable nutation angle experiment by varying either the amplitude or width of the excitation pulse."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "RabiAmp(q, np.linspace(0,1,101), showPlot=True) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "RabiWidth(q, np.arange(10e-9, 1e-6, 10e-9), showPlot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Coherence Time Measurements\n",
    "### T$_1$\n",
    "T$_1$ can be measured with an inversion recovery variable delay experiment. The sequence helper function tacks on calibration experiments that can be controlled with the ``calRepeats`` keyword argument."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "InversionRecovery(q,np.arange(100e-9,10e-6,100e-9), showPlot=True, calRepeats=2) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### T$_2$\n",
    "\n",
    "T$_2^*$ is usually characterized with a 90-delay-90 experiment where as the Hahn echo removes low frequency noise and that causes incoherent loss and recovers something closer to the true T$_2$. The delay parameter is the pulse spacing and so the total effective delay in the Hahn echo will be 2 times this plus the 180 pulse length."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ramsey(q, np.arange(100e-9,10e-6,100e-9), showPlot=True) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HahnEcho(q, np.arange(100e-9,10e-6,100e-9), showPlot=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
